<?php

$category_parent1 = mysql_query("SELECT categoryname, link FROM category where parent=0");
$category1 = mysql_query(@"
	SELECT COUNT(*) AS quantity, c.`categoryname`, c.`link`, c.idcategory
	FROM `category` c
		INNER JOIN `product` p 
			ON c.`idcategory` = p.`idcategory`
	WHERE parent!=0
	GROUP BY c.`idcategory`");

while ($row = mysql_fetch_array($category_parent1)) {
	$category_parent[] = $row;
}

while ($row = mysql_fetch_array($category1)) {
	$category[] = $row;
}
$smarty->assign("category_parent", $category_parent);
$smarty->assign("category", $category);
$query = mysql_query("select * from ads");
while ($row = mysql_fetch_array($query)) {
	$ads[] = $row;
}
$smarty->assign("ads", $ads);

// hiển thị trên menu tổng số sp
if (isset($_SESSION['cart']))
	$session_cart = count($_SESSION['cart']);
else
	$session_cart = 0;

$smarty->assign("quantity_cart_product", $session_cart);
// end - hiển thị trên menu tổng số sp
$countproduct = mysql_query(@"select count(idproduct) from product");
$row = mysql_fetch_array($countproduct);
$recordproduct = $row[0];
$smarty->assign("recordproduct", $recordproduct);

$counter = "./counter.txt";
$today = getdate();
$month = $today['month'];
$mday = $today['mday'];
$year = $today['year'];
$current_date = $mday . $month . $year;
// Log visit; 
$fp = fopen($counter, "a");
$line = $_SERVER['REMOTE_ADDR'] . "|" . $mday . $month . $year . "\n";
$size = strlen($line);
fputs($fp, $line, $size);
fclose($fp);
$contents = file($counter);
$total_hits = sizeof($contents);
$total_hosts = array();
for ($i = 0; $i < sizeof($contents); $i++) {
	$entry = explode("|", $contents[$i]);
	array_push($total_hosts, $entry[0]);
}
$total_hosts_size = sizeof(array_unique($total_hosts));
$daily_hits = array();
for ($i = 0; $i < sizeof($contents); $i++) {
	$entry = explode("|", $contents[$i]);
	if ($current_date == chop($entry[1])) {
		array_push($daily_hits, $entry[0]);
	}
}
$daily_hits_size = sizeof($daily_hits);
$daily_hosts = array();
for ($i = 0; $i < sizeof($contents); $i++) {
	$entry = explode("|", $contents[$i]);
	if ($current_date == chop($entry[1])) {
		array_push($daily_hosts, $entry[0]);
	}
}
$daily_hosts_size = sizeof(array_unique($daily_hosts));
$smarty->assign("daily_hits_size", $daily_hits_size);
$smarty->assign("total_hits", $total_hits);

//tinhot
$sql=  mysql_query(@"select * from article limit 0,2");
while($row=  mysql_fetch_array($sql))
{
	$result[]=$row;
}

$smarty->assign("result", $result);